package com.wj.community.dto;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * @author WangJian
 * @title: PageinationDTO
 * @projectName community
 * @description: TODO
 * @date 2019/8/14 22:52
 */
@Data
public class PaginationDTO {
    private List<QuestionDTO> questions;
    private Boolean showPrevious;
    private Boolean showFirstPage;
    private Boolean showNext;
    private Boolean showEndPage;
    private Integer page;
    private List<Integer> pages = new ArrayList<>();
    private Integer totalPage;
    public void setPagination(Integer totalCount, Integer page, Integer size) {
        this.page = page;
        totalPage = (totalCount % size == 0 ? totalCount / size : (totalCount / size + 1));
        pages.add(page);
        for (int i = 1; i <= 3; i++) {
            if (page - i > 0) {
                pages.add(0, page - i);
            }
            if (page + i <= totalPage) {
                pages.add(page + i);
            }
        }
        //是否展示上一页
        showPrevious = (page != 1);
        //是否展示下一页
        showNext = (!page.equals(totalPage));
        //是否展示第一页
        showFirstPage = (!pages.contains(1));
        //是否展示最后一页
        showEndPage = (!pages.contains(totalPage));


    }
}
